package com.misty.dao.dto;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.misty.common.Util.TimeUtil;
import com.misty.dao.domain.Users;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Map;

@Data
@TableName(value = "blog")
public class BlogDto {

    private Integer id; //id
    private String title; //标题
    private String content; //内容
    private String firstPicture; //首图
    private Integer likesCount; //点赞数
    private Integer collectionCount; //收藏数
    private String flag; //标记
    private Integer views; //浏览次数
    private boolean appreciation; //赞赏开启
    private boolean shareStatement; //版权开启
    private boolean commentabled; //评论开启
    private boolean published; //发布
    private boolean recommend; //推荐

    private String Summary; //摘要
    private String disTimeSpan; //距离时间跨度
//    private String tag; //标签
    private LocalDateTime createTime ; //创建时间
    private LocalDateTime updateTime; //更新时间

    @TableField(value = "user_id")
    private Integer userId;

    @TableField(exist = false)
    private String username;

    @TableField(exist = false)
    private Users user;

    public String getSummary() {
        if(content.length() > 255){
            return content.substring(0,255);
        }
        return content.substring(0,content.length());
    }

    public String getDisTimeSpan() {
        if(ObjectUtil.isEmpty(createTime)){
            return "";
        }
        Map disTime = TimeUtil.getDisTime(createTime, null);
        return disTime.get("time").toString() + disTime.get("unit").toString();
    }
}

